<template>
	<view>
		<template v-if="list.length > 0">
			<!-- 消息列表 -->
			<block v-for="(item,index) in list" :key="index">
				<msg-list :item="item" :index="index"></msg-list>
			</block>
		</template>
		<template v-else>
			<no-thing></no-thing>
		</template>
		
		<!-- 弹出层 -->
		<uni-popup ref="popup" type="top">
			<view class="flex align-center justify-center font-md border-bottom py-2" hover-class="bg-light" @click="popupEvent('friend')">
				<text class="iconfont icon-sousuo mr-2"></text> 添加好友
			</view>
			<view class="flex align-center justify-center font-md py-2" hover-class="bg-light"  @click="popupEvent('clear')">
				<text class="iconfont icon-shanchu mr-2"></text> 清除列表
			</view>
		</uni-popup>
		
	</view>
</template>

<script>
	const demo = [{
		avatar:"https://tangzhe123-com.oss-cn-shenzhen.aliyuncs.com/Appstatic/qsbk/demo/userpic/2.jpg",
		username:"张三",
		update_time:1570718427,
		data:"靓仔，在吗",
		noread:1
	},{
		avatar:"https://tangzhe123-com.oss-cn-shenzhen.aliyuncs.com/Appstatic/qsbk/demo/userpic/3.jpg",
		username:"王五",
		update_time:1570718427,
		data:"帝莎编程学院",
		noread:5
	},{
		avatar:"https://tangzhe123-com.oss-cn-shenzhen.aliyuncs.com/Appstatic/qsbk/demo/userpic/4.jpg",
		username:"李四",
		update_time:1570718427,
		data:"这是全栈开发吗",
		noread:3
	},{
		avatar:"https://tangzhe123-com.oss-cn-shenzhen.aliyuncs.com/Appstatic/qsbk/demo/userpic/5.jpg",
		username:"小六",
		update_time:1570718427,
		data:"支持小程序吗",
		noread:2
	}];
	
	import msgList from '@/components/msg/msg-list.vue';
	import noThing from '@/components/commons/no-thing.vue';
	import uniPopup from '@/components/uni-ui/uni-popup/uni-popup.vue';
	export default {
		components: {
			msgList,
			noThing,
			uniPopup
		},
		data() {
			return {
				list:[]
			}
		},
		// 页面加载
		onLoad() {
			this.list = demo
		},
		// 监听下拉刷新
		onPullDownRefresh() {
			this.refresh()
		},
		// 监听原生导航栏按钮事件
		onNavigationBarButtonTap(e) {
			switch (e.index){
				case 0: // 左边
					uni.navigateTo({
						url: '../user-list/user-list',
					});
					// 关闭弹出层
					this.$refs.popup.close()
					break;
				case 1: // 右边
					this.$refs.popup.open()
					break;
			}
		},
		methods: {
			// 下拉刷新
			refresh(){
				setTimeout(()=>{
					this.list = demo
					// 停止下拉刷新
					uni.stopPullDownRefresh()
				}, 2000)
			},
			// 弹出层选项点击事件
			popupEvent(e){
				switch (e){
					case 'friend':
						uni.navigateTo({
							url: '/pages/commons/search/search?type=user',
						});
						break;
					case 'clear':
						console.log('清除列表');
						break;
				}
				// 关闭弹出层
				this.$refs.popup.close()
			}
		}
	}
</script>

<style>

</style>
